package com.itheima.dao.system;

import com.itheima.dao.BaseDao;
import com.itheima.domain.system.Dept;
import com.itheima.domain.system.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserDao extends BaseDao<User> {

    @Select("SELECT * FROM ss_user")
    @Results(id="userResults",value = {
        @Result(property = "id",column = "user_id"),
        @Result(property = "email",column = "email"),
        @Result(property = "userName",column = "user_name"),
        @Result(property = "password",column = "password"),
        @Result(property = "state",column = "state"),
        @Result(property = "gender",column = "gender"),
        @Result(property = "telephone",column = "telephone"),
        @Result(property = "birthday",column = "birthday"),
        @Result(property = "joinDate",column = "join_date"),
        @Result(property = "deptId",column = "dept_id"),
        @Result(
                property = "dept",
                column = "dept_id",
                javaType = Dept.class,
                one = @One(select = "com.itheima.dao.system.DeptDao.findById")
        )
    })
    @Override
    List<User> findAll() throws Exception;

    @Select("select * from ss_user where user_id = #{xx}")
    @ResultMap("userResults")
    @Override
    User findById(String id) throws Exception;


    @Insert("insert into ss_user(user_id,email,user_name,password,state,gender,telephone,birthday,join_date,dept_id) values(#{id},#{email},#{userName},#{password},#{state},#{gender},#{telephone},#{birthday},#{joinDate},#{deptId})")
    @Override
    int save(User user) throws Exception;

    @Update("update ss_user set email=#{email},state=#{state}, gender=#{gender}, telephone=#{telephone}, birthday=#{birthday}, join_date=#{joinDate}, dept_id=#{deptId} where user_id=#{id}")
    @Override
    int update(User user) throws Exception;


    @Delete("delete from ss_user where user_id = #{id}")
    @Override
    int delete(String id) throws Exception;
}
